do
-- Event
Event = {}

function Event:New(o)
    local event = o or {}
    setmetatable(event, self)
    self.__index = self
    self.__call = self:Call()
    return event
end

function Event:Add(source,func)
    table.insert(self, {source,func})
end

function Event:Call(...)
    for _,item in ipairs(self) do
        item[2](item[1],... )
    end
end

-- Window

Window = {name="metatable"}

function Window:Init( ... )
    Button:ClickEvent():Add(self,self:Button_OnClick(Button))
end


function Window:Button_OnClick( sender )
    print(sender.name.." click on window "..self.name)
end

-- Button
Button = {name="button1"}

function Button:ClickEvent(o)
    local event = Event:New()-- body
    return event
end

Window:Init()

end